<!doctype html>
<html lang="en">

<head>
	<title>Home</title>
	{%include file="public/head_common" /%}
</head>

<body>
	<!-- WRAPPER -->
	<div id="wrapper">
		<div class="main">
			<!-- MAIN CONTENT -->
			<div class="main-content">
				<div class="container-fluid">
					<form class="form-horizontal" role="form" id="form1" method="post" action="{%:url('Goods/goodsHandle').'?id='.$goods['id']%}" onkeydown="if(event.keyCode==13){return false;}">
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">图片</label>
							<div class="col-sm-4">
								<input type="file" class="form-control" name="picture">
							</div>
							<div class="col-sm-1"><img src="{%$goods.picture%}" id="preview" height="220" style="position: absolute;"></div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">商品类别</label>
							<div class="col-sm-4">
								<select class="form-control" name="cate_id">
									<option value=""> - 选择 - </option>
									{%volist name="categories" id="cate"%}
									<option value="{%$cate.id%}" {%$cate.id==$goods.cate_id ? 'selected' : ''%}>{%$cate.type%} - {%$cate.name%}</option>
									{%/volist%}
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="firstname" class="col-sm-2 control-label">品牌</label>
							<div class="col-sm-4">
								<select class="form-control" name="brand_id">
									<option value=""> - 选择 - </option>
									{%volist name="brands" id="brand"%}
									<option value="{%$brand.id%}" {%$brand.id==$goods.brand_id ? 'selected' : ''%}>{%$brand.first_letter%} - {%$brand.name%}</option>
									{%/volist%}
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">商品描述</label>
							<div class="col-sm-4">
								<input type="text" class="form-control" name="description" placeholder="请输入商品描述" value="{%$goods.description%}">
							</div>
						</div>
						<!-- <div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">成本价</label>
							<div class="col-sm-4">
								<input type="number" class="form-control" name="goods_price" placeholder="请输入商品成本价" value="{%$goods.goods_price%}">
							</div>
						</div> -->
						<div class="form-group">
							<label for="lastname" class="col-sm-2 control-label">尺码组</label>
							<div class="col-sm-4">
								<select class="form-control" name="size_set">
									<option value="">-请选择-</option>
									{%volist name='size_sets' id='size_set'%}
									<option value="{%$key%}" {%$key==$goods.size_set ? 'selected' : ''%}>{%$size_set%}</option>
									{%/volist%}
								</select>
							</div>
						</div>
						<div class="form-group">
							<div class="col-sm-offset-2 col-sm-10">
								<button type="submit" class="btn btn-primary">保存</button>
							</div>
						</div>
					</form>
				</div>
			</div>
			<!-- END MAIN CONTENT -->
		</div>
		<!-- END MAIN -->
		<div class="clearfix"></div>
		<!-- FOOTER -->
		{%include file="public/footer" /%}
		<!-- END FOOTER -->
	</div>
	<!-- END WRAPPER -->
	<!-- Javascript -->
	<script src="__STATIC__/assets/vendor/jquery/jquery.min.js"></script>
	<script src="__STATIC__/assets/vendor/bootstrap/js/bootstrap.min.js"></script>
	<script src="__STATIC__/assets/vendor/jquery.form.js"></script>
	<script src="__STATIC__/assets/vendor/layer-v3.1.1/layer/layer.js"></script>
	<!-- <script src="__STATIC__/assets/scripts/klorofil-common.js"></script> -->
	<script type="text/javascript">
		var options = {
	        //beforeSubmit:  showRequest,  // pre-submit callback   
	        success:       function(rsp){
	        	var opt = {
	        		type: 0,
	        		content: rsp.msg,
	        		closeBtn: 0,
	        		yes: function(index) {
	        			layer.close(index); //如果设定了yes回调，需进行手工关闭
	        			if (rsp.code>0) {
				  			parent.location.reload();
				  		}
	        		}
	        	};//layer的配置项
	        	if (rsp.code==0) {
	        		opt['icon'] = 2;
	        	} else {
	        		opt['icon'] = 1;
	        	}
	        	console.log(opt);
	        	layer.open(opt);
	        }, 
	        // other available options:   
	        //url:       "{:url('Goods/goodsHandle')}",        // override for form's 'action' attribute   
	        //type:      'post',        // 'get' or 'post', override for form's 'method' attribute   
	        dataType:  'json',        // 'xml', 'script', or 'json' (expected server response type)   
	        //resetForm: true,        // reset the form after successful submit   
    	};   
   		
	    // bind to the form's submit event   
	    $('#form1').submit(function() {   
	        $(this).ajaxSubmit(options);
	        // !!! Important !!!   
	        // always return false to prevent standard browser submit and page navigation   
	        return false;   
	    });  
	    $("input[type='file']").change(function(){
	    	$("#preview").attr("src",URL.createObjectURL($(this)[0].files[0]));
	    });
	</script>
	
</body>

</html>